<?php
/**
 * Created by PhpStorm.
 * User: lei
 * Date: 15-6-4
 * Time: 下午9:10
 */
use Phalcon\Mvc\Model;
class BusinessUsers extends Model
{
    public $id;

    public $user;

    public $serverUserId;

    public $businessSystemId;

    public $addTime;

    public $updateTime;

    public $active;

    public function initialize()
    {
        /*$this->belongsTo('businessSystemId', 'BusinessSystems', 'id', array(
            'reusable' => true
        ));*/
        $this->belongsTo('businessSystemId', 'BusinessSystems', 'id');
        $this->belongsTo('serverUserId', 'ServerUsers', 'id');
    }

    /**
     * Returns a human representation of 'active'
     *
     * @return string
     */
    public function getActiveDetail()
    {
        if ($this->active == 'Y') {
            return 'Yes';
        }
        return 'No';
    }
    
    public function getUserNameById($id)
    {
        $conditions = " id = :id:";
        $parameters = array('id' => "$id");
	    $serverUsers = ServerUsers::findFirst(array($conditions, "bind" => $parameters));
	    return $serverUsers->name;
    }

    public function searchServerUsers()
    {
        $serverUser = new ServerUsersController();
        $serverUser->searchAction();
    }
}